package com.jwmp.rbac.service.impl;

import com.jwmp.rbac.domain.Module;
import com.jwmp.rbac.mapper.ModuleMapper;
import com.jwmp.rbac.service.IModuleService;
import com.jwmp.core.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ModuleServiceImpl implements IModuleService {

    public Long insert(Module module) {
        SqlSession session = MyBatisUtil.openSession();
        ModuleMapper moduleMapper = session.getMapper(ModuleMapper.class);
        moduleMapper.insert(module);
        session.commit();
        session.close();
        return module.getId();
    }

    public List<Module> selectBaseList() {
        SqlSession session = MyBatisUtil.openSession();
        ModuleMapper moduleMapper = session.getMapper(ModuleMapper.class);
        List<Module> list = moduleMapper.selectBaseList();
        session.close();
        return list;
    }

    public List<Module> selectRoleNoPermissionModules(Long roleId) {
        SqlSession session = MyBatisUtil.openSession();
        ModuleMapper moduleMapper = session.getMapper(ModuleMapper.class);
        List<Module> modules = moduleMapper.selectRoleNoPermissionModules(roleId);
        session.close();
        return modules;
    }
}
